Optionally check the solution at the end of the run #30
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Addresses #17 by implementing a function (
check_solution) that checks whether the unitary operator for the synthesized sequence of gates is sufficiently close to the desired unitary operator for the rotation gate.Update:
As per @jlapeyre's comment, it is in fact not too difficult to directly compute the operator norm for a 2x2 matrix. Letting
$A = R_z(\theta) - U$ , with
(where$x = e^{-i \theta / 2}$ ), the eigenvalues of $A^* A$ can be computed as $\lambda = 2 - (x^* u + u^* x)$ , and the operator norm is given as $\sqrt \lambda$ . This is close but still a bit different from the formula in pygridsynth.
@jlapeyre, one question: what is the best way to handle the result? I was not sure if we should raise an error or handle the result in some other way, so currently it just print to the screen whether the solution is correct or not. But we want something better (in particular for adding a few integration tests).
A new argument
check_solutiontoGridSynthConfig, which can be instantiated from command line by specifying--checkand from external code by specifyingconfig_from_theta_epsilon(...).with_check_solution(true). Btw, this is a nice pattern that avoids updating the calling code when new arguments are added toGridSynthConfig.